import axios from 'axios'
const requestUrl = ["http://10.5.22.158:9090/api/","http://39.172.58.29:9090/api/", "http://10.10.121.124:9090/api/"];
let typeNum = 1;//标记位,0测试环境，1正式环境公网，2内网
let request = axios.create({
    baseURL: requestUrl[typeNum],
    timeout: 20000,
    headers: {
        'Content-Type': 'application/json;charset=utf-8'
    }
})
request.interceptors.response.use(
    response => {
        if (response.status == 200) {
            return response
        }
        // return Promise.reject(response)
    },
    error => {
        return Promise.reject(error)
    }
)
export function requestAPI(url, type, requestBody) {
    // testRequest.defaults.headers.common['authorization'] = getCookie('login_tokens')
    return request({
        'url': requestUrl[typeNum]+url,
        'method': type,
        // 'Content-Type': 'application/json;charset=utf-8',
        'Content-Type': 'application/x-www-form-urlencoded',
        // 'data': JSON.stringify(requestBody || {})
        'data': type === 'post' ? requestBody : {},
        'params': type === 'get' ? requestBody : {}
    })
}